package com.xujc.entity;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.context.annotation.Lazy;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Collection;

/**
 * Created by xujc on 6/16/15.
 */
@Entity
@Table(name = "discuse", schema = "", catalog = "test")
@DynamicInsert(true)
@DynamicUpdate(true)
@Lazy(value = false)
public class DiscuseEntity {
    private int mDId;
    private int mUId;
    private int mFId;
    private String mContent;
    private Timestamp mLastEdit;
    private Timestamp mPublishTime;
    private String mImages;
    private FormEntity mFormByFId;
    private UserEntity mUserByUId;
    private Collection<ReviewEntity> mReviewsByDId;

    @Id
    @Column(name = "d_id")
    @GeneratedValue
    public int getDId() {
        return mDId;
    }

    public void setDId(int DId) {
        mDId = DId;
    }

    @Basic
    @Column(name = "u_id")
    public int getUId() {
        return mUId;
    }

    public void setUId(int UId) {
        mUId = UId;
    }

    @Basic
    @Column(name = "f_id")
    public int getFId() {
        return mFId;
    }

    public void setFId(int FId) {
        mFId = FId;
    }

    @Basic
    @Column(name = "content")
    public String getContent() {
        return mContent;
    }

    public void setContent(String content) {
        mContent = content;
    }

    @Basic
    @Column(name = "last_edit")
    public Timestamp getLastEdit() {
        return mLastEdit;
    }

    public void setLastEdit(Timestamp lastEdit) {
        mLastEdit = lastEdit;
    }

    @Basic
    @Column(name = "publish_time")
    public Timestamp getPublishTime() {
        return mPublishTime;
    }

    public void setPublishTime(Timestamp publishTime) {
        mPublishTime = publishTime;
    }

    @Basic
    @Column(name = "images")
    public String getImages() {
        return mImages;
    }

    public void setImages(String images) {
        mImages = images;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        DiscuseEntity that = (DiscuseEntity) o;

        if (mContent != null ? !mContent.equals(that.mContent) : that.mContent != null) return false;
        if (mLastEdit != null ? !mLastEdit.equals(that.mLastEdit) : that.mLastEdit != null) return false;
        if (mPublishTime != null ? !mPublishTime.equals(that.mPublishTime) : that.mPublishTime != null) return false;
        if (mImages != null ? !mImages.equals(that.mImages) : that.mImages != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = mContent != null ? mContent.hashCode() : 0;
        result = 31 * result + (mLastEdit != null ? mLastEdit.hashCode() : 0);
        result = 31 * result + (mPublishTime != null ? mPublishTime.hashCode() : 0);
        result = 31 * result + (mImages != null ? mImages.hashCode() : 0);
        return result;
    }

    @ManyToOne
    @JoinColumn(name = "f_id", referencedColumnName = "f_id", nullable = false,updatable = false,insertable = false)
    @Lazy(value = false)
    public FormEntity getFormByFId() {
        return mFormByFId;
    }

    public void setFormByFId(FormEntity formByFId) {
        mFormByFId = formByFId;
    }

    @ManyToOne
    @JoinColumn(name = "u_id", referencedColumnName = "u_id", nullable = false,updatable = false,insertable = false)
    public UserEntity getUserByUId() {
        return mUserByUId;
    }

    public void setUserByUId(UserEntity userByUId) {
        mUserByUId = userByUId;
    }

    @OneToMany(mappedBy = "discuseByDId")
    public Collection<ReviewEntity> getReviewsByDId() {
        return mReviewsByDId;
    }

    public void setReviewsByDId(Collection<ReviewEntity> reviewsByDId) {
        mReviewsByDId = reviewsByDId;
    }
}
